package com.goldcn.enums;

import com.goldcn.interceptor.SystemContext;
import com.goldcn.user.model.Organizational;
import com.goldcn.user.service.OrganizationalService;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * Created by Administrator on 2016/10/18.
 */
public class TopDeptEnum {

    private Integer seq;
    private Long deptID;//总部
    private String deptName;
    private Long companyID;

    TopDeptEnum(Long deptID,String deptName,Long companyID) {
        this.deptID = deptID;
        this.deptName = deptName;
        this.companyID = companyID;
    }

    public Integer getSeq() {
        return seq;
    }

    public void setSeq(Integer seq) {
        this.seq = seq;
    }

    public Long getDeptID() {
        return deptID;
    }

    public void setDeptID(Long deptID) {
        this.deptID = deptID;
    }

    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    public Long getCompanyID() {
        return companyID;
    }

    public void setCompanyID(Long companyID) {
        this.companyID = companyID;
    }

    public static TopDeptEnum valuekOf(Long companyID) {
        BeanFactory factory = WebApplicationContextUtils.getRequiredWebApplicationContext(SystemContext.getRequest().getServletContext());
        OrganizationalService organizationalService = (OrganizationalService) factory.getBean("organizationalService");
        Organizational organizational = organizationalService.selectTopDept(companyID);
        if(organizational == null){
           return null;
        }
        TopDeptEnum topDeptEnum = new TopDeptEnum(organizational.getoID(),organizational.getOrganizationalName(),companyID);
        return topDeptEnum;
    }
}
